#!/usr/bin/perl
#  Copyright (c) 2011 Google Inc.
# 
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
# 
#      http://www.apache.org/licenses/LICENSE-2.0
# 
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

# This script generates the orkutdevbox.SAMPLES[] array from the samples
# files passed to it in the command line. Each sample file will be
# included in the array as { name: '(sample name)', code: '(code)' }.
# The name of the sample is simply the file name with '_' replaced by ' '
# and the code is the content of the file.

print "orkutdevbox.SAMPLES = [\n";
$needs_comma = 0;

for $sample_src (@ARGV) {
   $sample_src =~ /(?:\/|^)([^\/]+)\.\w+$/ 
                        or die "Invalid sample path: $sample_src";
   $name = $1; $name =~ s/_/ /g;

   $code = `cat $sample_src`;
   $code =~ s/\\/\\\\/g;
   $code =~ s/\n/\\n/g;
   $code =~ s/'/\\'/g;

   # we can't have an embedded literal "</script>", so break it up
   $code =~ s/<\/script/<' + '\/script/g;
   
   print ",\n" if $needs_comma;
   print "   { name: '$name', code: '$code' }";
   $needs_comma = 1;
}

print "\n];\n";

